package algorithm.easy;

public class Solution108 {

    //输入：nums = [-10,-3,0,5,9]
    //输出：[0,-3,9,-10,null,5]
    //解释：[0,-10,5,null,-3,null,9] 也将被视为正确答案：
    public static TreeNode sortedArrayToBST(int[] nums) {

        return build(nums,0,nums.length-1);
    }

    public static TreeNode build(int[] nums,int left ,int right){
        if(left>right){
            return null;
        }
        int mid = left+((right-left)>>1);
        TreeNode node = new  TreeNode(mid);
        node.left = build(nums,left,mid-1);
        node.right = build(nums,mid+1,right);
        return node;

    }

    public static void main(String[] args){
        int[] nums = {-10,-3,0,5,9};
        sortedArrayToBST(nums);
    }
}
